package com.spark.msb.spark

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @description:
 * @time: 2020/11/26 22:48
 * @author: lhy
 */
object WordCountScala {
    def main(args: Array[String]): Unit = {
        val conf: SparkConf = new SparkConf().setAppName("WordCountScala").setMaster("local")
        val sc = new SparkContext(conf)
        val fileRDD: RDD[String] = sc.textFile("data.txt/english_new.txt")
        val wordCount: RDD[(String, Int)] = fileRDD.flatMap(lines => lines.split(" "))
                        .map(word => (word,1))
                        .reduceByKey(_+_).sortBy(_._2,false)
        wordCount.collect()
        wordCount.foreach(println)
    }
}
